package com.profgj.profgj.config;

import com.github.xiaoymin.swaggerbootstrapui.annotations.EnableSwaggerBootstrapUI;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * 使用swagger2 配置一定要标记上配置类
 */
@Configuration
/**
 * 启用swagger2在线文档生成功能
 */
@EnableSwagger2
/**
 * 使用swagger2-bootstrap-ui 界面模板
 */
@EnableSwaggerBootstrapUI
public class SwaggerConfiguration {
    /**
     * 创建API文档Doc
     * @return
     */
    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.profgj.profgj.controller"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * API文档配置
     * @return
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("发改局企业能耗管理系统 RESTful APIs")
                .description("发改局企业能耗管理系统")
                .termsOfServiceUrl("http://localhost:8080/")
                .contact("chengzhouyun@mail.com")
                .version("1.0")
                .build();
    }

//    http://localhost:8080/doc.html

}

